home *** CD-ROM | disk | FTP | other *** search
- Path: news.Gsu.EDU!gs01lmh
- From: gs01lmh@panther.Gsu.EDU (Louis Miller Hall)
- Newsgroups: comp.lang.c++
- Subject: Something Funny Going On Here?!?
- Date: 24 Feb 1996 01:02:25 GMT
- Organization: Georgia State University
- Message-ID: <4glo31$boc@sphinx.Gsu.EDU>
- NNTP-Posting-Host: panther.gsu.edu
- NNTP-Posting-User: gs01lmh
- X-Newsreader: TIN [version 1.2 PL2]
-
-
-
- I was wondering if anyone can help me here, no matter what data is
- entered, I cannot get the array h[i] to get any value other than 0 in any
- ith position, which causes me to get a divide by 0 on the next line, I
- have copied this algorithm directly from a textbook, and have traced the
- problem line by line and have found that the error occurs here, but I
- cannot understand why, any help or insight would be appreciated.
-
- Thanks
-
- Louis
-
- I have eliminated non-essential code:
-
-
-
-
- #define MAX_ENTRIES 10
- #define MAXCHARS 81
- #include <fstream.h>
-
- int i,
- j,
- // loop control variables
- n; // number
- of data points that are given
-
- double x[MAX_ENTRIES], // the x0...xn's that are given in the data
- a[MAX_ENTRIES], // the values of f(x)'s, defined
- in the algorithm
- b[MAX_ENTRIES],
- c[MAX_ENTRIES],
- d[MAX_ENTRIES], // what will be the coeefficients
- of the cubic spline
- l[MAX_ENTRIES],
- u[MAX_ENTRIES],
- alpha[MAX_ENTRIES];
- z[MAX_ENTRIES],
- h[MAX_ENTRIES]; // intermediate caluclation variables
-
-
-
- void main ()
- { // main
- // get all input data in input step of algorithm
- cout << "This program will develop the cubic spline interpolant S for
- the "
- << "function f " << endl << "defined at the numbers
- x[0]...x[n]" << endl
- << endl;
-
-
- // begin loop to continue getting data until the user is finished
-
- while (1)
- { // while
-
- cout << endl << "How many data points 0 to quit>";
- cin >> n;
- if (n==0) break;
-
-
- cout << endl << "Enter the x[n] values:" << endl;
- for (i=0; i < n; i++)
- { // for
- cout << "x[" << i << "] = ";
- cin >> x[i];
- } // for
-
- cout << endl << "Now enter the f(x) values:" << endl;
-
- // will display f(actual x) and will directly put that into a[x]
- per alg.
- for (i=0; i<n; i++)
- { // for
- cout << "f[" << x[i] << "] = ";
- cin >> a[i];
- } // for
-
- // Step 1
-
- //________________________________________________________
- // I CANNOT GET ANY h[i] TO GET A VALUE OTHER THAN 0 HERE??!!??
- for (i=0; i<n-1; i++)
- h[i] = (x[i+1] - x[i]);
- //________________________________________________________
- // step 2
- for (i=1; i<=n-1; i++)
- alpha[i] = ((3/h[i])*(a[i+1] - a[i]))-((3/h[i-1])*(a[i]-a[i-1]));
-
- // AND THE DIVIDE BY ZERO OCCURRS HERE
-